var Kuo_Tools = {
    /*获取时间戳 */

    Time(){
        return Date.parse(new Date())/1000;
    },Mulu:(mulu)=>{
        var mulu = mulu.split("/");
        if(mulu.length > 1){
            mulu.pop();
            return  mulu.join("/")+'/';
        }
        return "/";

    },Fenye:( $MEYE , $TOTAL  ,$GESHU, $PAGE,$URLQ,$URLH )=>{
        /*html 分页*/
        if(!$MEYE || $MEYE < 1)$MEYE = 10;
        if(!$TOTAL)$TOTAL =0;
        if(!$GESHU) $GESHU = 1;
        if(!$PAGE)$PAGE = 1;
        if(!$URLQ)$URLQ = "";
        if(!$URLH)$URLH = "";
        $PAGE = Mode("Tools").Int($PAGE);
        if($PAGE<1){
            $PAGE = 1;
        }

        let YUYAN = {
            'dqdi':'当前',
            'ye':'页',
            'home': '首页',
            'last':'上一页',
            'next' :'下一页',
            'weiye':'尾页'
        }
        let ZONGYE = Math.ceil($TOTAL/ $MEYE);
        if($PAGE  > ZONGYE){
            $PAGE  = ZONGYE;
        }
        let  $subPageCss2Str = "";
        if($GESHU >= 0){
            $subPageCss2Str+='<span class="kuo_dqdi">'+YUYAN.dqdi+"("+$PAGE+"/"+ZONGYE+")"+YUYAN.ye+'</span>';
            $subPageCss2Str+='<a  class="kuo_home" href="'+RTrim($URLQ,FENGE)+$URLH+'">'+YUYAN.home+'</a>';
        }
        let shang = $PAGE-1;
        let xia = $PAGE+1;
        if(shang <=0){  
            $subPageCss2Str+='<span class="kuo_last">'+YUYAN.last+'</span>';
        }else if(shang > ZONGYE ){
            $subPageCss2Str+='<a  class="kuo_last" href="'+$URLQ+(ZONGYE-1)+$URLH+'">'+YUYAN.last+'</a>';
        }else{

            if(shang ==1 ){
                $subPageCss2Str+='<a  class="kuo_last" href="'+RTrim($URLQ,FENGE)+$URLH+'">'+YUYAN.last+'</a>';
            }else{
                $subPageCss2Str+='<a  class="kuo_last" href="'+$URLQ+shang+$URLH+'">'+YUYAN.last+'</a>';
            }
        }
        if($GESHU >= 0){
            let dong = Math.ceil($GESHU/2);
            if(ZONGYE < $GESHU ){
                $GESHU = ZONGYE;
            }
            if( $PAGE <=  dong){
                for(let $i = 1; $i <= $GESHU; $i ++){
                    let geshu = $i;
                    if(geshu == $PAGE){
                        $subPageCss2Str+='<span class="kuo_page hover">' +geshu+"</span>";
                    }else{
                        $subPageCss2Str+='<a class="kuo_page" href="'+$URLQ+(geshu)+$URLH+'">'+geshu+'</a>';
                    }
                }

            }else if( $PAGE > ZONGYE - dong){

                for(let $i = ZONGYE-$GESHU+1; $i <= ZONGYE; $i ++){
                    let geshu = $i;
                    if(geshu == $PAGE){
                        $subPageCss2Str+='<span class="kuo_page hover">' +geshu+"</span>";
                    }else{
                        $subPageCss2Str+='<a class="kuo_page" href="'+$URLQ+(geshu)+$URLH+'">'+geshu+'</a>';
                    }
                }

            }else{

                let jia = $GESHU - dong;
                for(let $i = dong-1; $i >= 0; $i --){
                    let geshu = $PAGE-$i;
                    if(geshu == $PAGE){
                        $subPageCss2Str+='<span class="kuo_page hover">' +geshu+"</span>";
                    }else{
                        $subPageCss2Str+='<a class="kuo_page" href="'+$URLQ+(geshu)+$URLH+'">'+geshu+'</a>';
                    }
                    
                }
                for(let $i = 1; $i <= jia; $i ++){
                    let geshu = $PAGE+$i;
                    if(geshu == $PAGE){
                        $subPageCss2Str+='<span class="kuo_page hover">' +geshu+"</span>";
                    }else{
                        $subPageCss2Str+='<a class="kuo_page" href="'+$URLQ+(geshu)+$URLH+'">'+geshu+'</a>';
                    }
                }
            }
        }


        if(xia > ZONGYE){
            $subPageCss2Str+='<span class="kuo_next">'+YUYAN.next+'</span>';
        }else{
            $subPageCss2Str+='<a class="kuo_next" href="'+$URLQ+xia+$URLH+'">'+YUYAN.next+'</a>';
        }
        
        if($GESHU >= 0){
            $subPageCss2Str+='<a class="kuo_weiye" href="'+$URLQ+ZONGYE+$URLH+'">'+YUYAN.weiye+'</a>';
        }
        return $subPageCss2Str;


    },TIQUimg:( $neirong ,$xiaobiao  )=>{
        if(!$xiaobiao){
            $xiaobiao = -1;
        }
        if(!$neirong || $neirong == ""){
            if($xiaobiao >= 0){
                return "";
            }
            return [];
        }
        $neirong = str_replace(['"',"'"],["@","@"],$neirong+" ");
        var reg = /src=@(.*)@/igm;
        let $IMG = [];
        let jishu = 0;
        let tem = null;
        while( tem = reg.exec($neirong)){
            jishu++;
            if(jishu > 1000){
                break ;
            }
            if(tem[1] != ""){
                let shuzhi = tem[1].split("@");
                $IMG.push(shuzhi[0]);
            }
        }
        if(!$IMG || $IMG.length < 1){
            if($xiaobiao >= 0){
                return "";
            }else{
                return [];
            }
        }
        if($xiaobiao >= 0){
            for(var $i in $IMG ){
                if($i == $xiaobiao){
                    return $vv;
                }
            }
            return reset($IMG);
        }else{
            return $IMG;
        }
    
    },Int:(zhis)=>{
        zhis = parseInt(""+zhis);
        if(isNaN(zhis)){
            zhis = 0;
        }
        return Number(zhis*1);
    },Xss:(name)=>{
        if(!name){
            return "";
        }
        var Safety = {
            '<':'',
            '>':'',
            '=':'',
            '"':'',
            "'":'',
            'script':''
        }
        for(var yuan in Safety){
            name = name.replace(new RegExp(yuan,"igm"),Safety[yuan]);
        }
        return name;

    },Jine:(name)=>{
        if(!name){
            return 0;
        }
        if(isNaN(name)){
            return 0;
        }
        return (Math.floor(name * 100) / 100).toFixed(2);
    },FJine:(name)=>{
        if(!name){
            return 0;
        }
        if(isNaN(name)){
            return 0;
        }
        return (Math.floor(name * 100000) / 100000).toFixed(5);
    },GUoLV:(name)=>{
        if(!name){
            return name;
        }
        name = ""+name;
        return name.replace(/\.\./g,'');
    },
    /* uuid */
    Uuid (){ 
        var zifu = (""+Kuo_Tools.Time()).split("");
        return ('x'+zifu[1]+'x'+zifu[9]+'yx'+zifu[2]+'x-x'+zifu[3]+'xx-yx'+zifu[4]+'x-yx'+zifu[5]+'x-xxx'+zifu[6]+'x'+zifu[8]+'yxx'+zifu[7]+'xx').replace(/[xy]/g, function(c) {
            var r = Math.random()*36|0, v = c == 'x' ? r : (r&0x3|0x8);
            return v.toString(36);
        });
    },Date(fmt,shijia){
        if(!fmt)fmt ="Y-m-d H:i:s";
        if(!shijia)shijia = this.Time();
        
        let da= new Date(shijia*1000);
        var o = {
            'Y+': da.getFullYear(),
            'Y+': da.getFullYear(),
            'M+': da.getMonth() + 1,
            'm+': da.getMonth() + 1,
            'D+': da.getDate(),
            'd+': da.getDate(),
            'H+': da.getHours(),
            'h+': da.getHours(),
            'i+': da.getMinutes(),
            'I+': da.getMinutes(),
            's+': da.getSeconds(),
            'S+': da.getSeconds()
        };
          
        for (var k in o) {
            if (new RegExp('(' + k + ')').test(fmt)) {
                var tzhi = ""+o[k];
                if(tzhi.length  == 1){
                    o[k] = "0"+tzhi;
                }
              fmt = fmt.replace(RegExp.$1,   (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(String(o[k]).length)));
            }
        }
        return fmt;
    },UTC(){
        let da=new Date();
        da.setTime( da.getTime()  );
        return da.toUTCString();
    },
    /*cookies 过期时间*/
    SetCookieTiem(){
        let da=new Date();
        da.setTime( da.getTime() + Expiredseconds  );
        return da.toUTCString();
    }
    
};
module.exports = Kuo_Tools;